﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace StuDormManage
{
    public partial class frmLogin : Form
    {
       
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //SqlConnection cn;
            //cn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;;database=StuDormManage;uid=sa;password=123456;");
            //string strCn = "Data Source=(local)\\SQLEXPRESS;;database=StuDormManage;uid=sa;password=123456";
            string strCn = "Server=pc.hstc.cn; database=dhd2014112116;uid=2014112116;pwd=19960205";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strSql = "select count(*) from Login where Acount ='" + txtName.Text + "' and Password ='" + txtPwd.Text + "'";
                //string strSql = "SELECT   COUNT(*) AS cnt FROM      Student";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                cmd.CommandText = strSql;
                int iCount = (int)cmd.ExecuteScalar();
                this.lblJudge.Text = "记录数：" + iCount.ToString();
                if (txtName.Text == "")
                 {
                     lblJudge.Text = "用户名不能为空!";
                 }
                 else if (txtPwd.Text == "")
                 {
                     lblJudge.Text = "密码不能为空!";
                 }
                else if (iCount > 0)
                {
                    lblJudge.Text = "登录成功!";
                    frmMain fmain = new frmMain();
                    fmain.Show();
                    this.Hide();
                }
                else
                {
                    lblJudge.Text = "账号或密码错误!";
                }
            }
            catch (Exception ex)
            {
                this.lblJudge.Text = ex.Message;
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        

        private void FrmLogin_Load(object sender, EventArgs e)
        {

        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {

        }

        private void FrmLogin_Load_1(object sender, EventArgs e)
        {

        }

        private void btnRegit_Click(object sender, EventArgs e)
        {
            StuDormManage.frmRegit fRegit = new StuDormManage.frmRegit();
            fRegit.Show();
            this.Hide();
        }

        private void txtName_TextChanged_1(object sender, EventArgs e)
        {

        }
    }
}
